package com.wtwd.campus.controller;

import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.model.vo.ResultVO;
import com.wtwd.campus.utils.MyExcelUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author zdl
 * @Description
 * @create 2021-07-21 14:43
 */
@Api(tags = "系统管理")
@RestController
@RequestMapping("sys")
public class SysController {
    @ApiOperation("获取Excel导入模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateCode", value = "模板Code", required = true, dataTypeClass = Integer.class
                    , example = "1-教师2-学生3-设备4-三方客户设备")
    })
    @ApiResponses({@ApiResponse(code = 1, message = "模板下载成功,返回文件"),
            @ApiResponse(code = 500, message = "模板错误")
    })
    @GetMapping("/excelImportTemplate/{templateCode}")
    public ResultVO getExcelTemplate(@PathVariable("templateCode") Integer templateCode, HttpServletResponse httpServletResponse) {
        try {
            MyExcelUtils.downLoadExcelTemplate(templateCode, httpServletResponse);
        } catch (Exception e) {
            return ResultVO.error(RespCode.ERROR);
        }
        return null;
    }
}
